//
//  CCRTStatusBar.m
//  iSeal5200
//
//  Created by He Yuan on 12-12-17.
//  Copyright (c) 2012年 http://www.heyuan110.com. All rights reserved.
//

#import "StatusBar.h"

static CCRTStatusBar *statusBar = nil;

@implementation CCRTStatusBar

+(CCRTStatusBar *)shareCCRTStatusBar
{
    @synchronized(self)
    {
        if (statusBar == nil)
        {
            CGRect rect = [UIApplication sharedApplication].statusBarFrame;
            statusBar = [[CCRTStatusBar alloc]initWithFrame:rect];
        }
        return statusBar;
    }
    return nil;
}

- (id)initWithFrame:(CGRect)frame
{
    if ((self = [super initWithFrame:frame]))
    {
        CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
        self.windowLevel = UIWindowLevelStatusBar+1.f;
        self.frame = statusBarFrame;
		self.alpha = 1.0;
		self.hidden = YES;
        
        lblStatus = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, statusBarFrame.size.width, 25.0)];
        [lblStatus setBackgroundColor:[UIColor redColor]];
        [lblStatus setTextColor:[UIColor whiteColor]];
        lblStatus.font = FONT_MIDDLE_BOLD;
        [lblStatus setTextAlignment:UITextAlignmentCenter];
        [self addSubview:lblStatus];
    }
    return self;
}

-(void)showMessage:(NSString*)msg type:(CCRTStatusBarType)type
{
    switch (type)
    {
        case CCRTStatusBarTypeAlert:
            [lblStatus setBackgroundColor:[UIColor redColor]];
            break;
        case CCRTStatusBarTypeCommen:
            [lblStatus setBackgroundColor:[UIColor blackColor]];
        default:
            [lblStatus setBackgroundColor:[UIColor redColor]];
            break;
    }
}

- (void) showMessage:(NSString*) msg {
	if (!msg) return;
	lblStatus.text = msg;
    [lblStatus setBackgroundColor:[UIColor redColor]];
	self.hidden = NO;
}

- (void) hide
{
    lblStatus.text = @"";
	self.hidden = YES;
}

@end
